package com.jwaoo.chat.fragment.session;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.dx.as.TabTools;
import com.dx.as.ToolBarOptions;
import com.dx.as.UI;
import com.dx.as.fragment.TFragment;
import com.jwaoo.chat.ChatHelpter;
import com.jwaoo.chat.R;
import com.jwaoo.chat.activity.module.fromapp.AppInstance;
import com.jwaoo.chat.fragment.session.bean.SessionBean;
import com.jwaoo.chat.fragment.session.repository.ISessionInterface;
import com.jwaoo.chat.fragment.session.repository.SessionRep;
import java.util.List;

/**
 * Created by jwaoo on 2017/6/30.
 */

public class SessionActivity extends UI implements ISessionInterface {
    private RecyclerView recyclerView;
    private SessionRep sessionRep;
    private TabTools tabTools;

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        setContentView(R.layout.fragment_session);
        setToolbar(null);
        initData();
        initView();
    }

    private void initData(){
        sessionRep = new SessionRep(this,this);
        sessionRep.initialataData();
    }

    @Override
    public void onResume() {
        super.onResume();
        sessionRep.onResume();
    }


    @Override
    public void onPause() {
        super.onPause();
        sessionRep.onPause();
    }


    public void initView() {
        if (tabTools == null) {
            tabTools = new TabTools(onTabClickListener);
            tabTools.initView(getContentRoot(),new String[]{getResources().getString(R.string.tab_message),getResources().getString(R.string.tab_dynamic),getResources().getString(R.string.tab_follow)});
        }
        recyclerView = findView(R.id.recycler_view);
        recyclerView.setAdapter(sessionRep.getAdapter());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addOnItemTouchListener(sessionRep.getOnTouchListener());
    }


    @Override
    public void onItemClick(final SessionBean sessionBean) {
        ChatHelpter.currentSessionId = sessionBean.getFriend();
        AppInstance.getInstance().startChatting(sessionBean.getFriend());
    }

    @Override
    public void getSessionList(Object object) {
        List<SessionBean> list = (List<SessionBean>) object;
    }

    @Override
    public void updateUnReadCount(int count) {
        AppInstance.getInstance().updateUnReadCount(count,false);
    }

    private TabTools.OnTabClickListener onTabClickListener = new TabTools.OnTabClickListener() {
        @Override
        public void onTabClick(int option) {

        }
    };
}
